package com.itfenghuang.util;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;

import javax.crypto.SecretKey;
import java.util.Date;
import java.util.Map;

public class JwtUtil {
    //1.自定义秘钥
    static String sect="dbasdjsakbdDSAFASFAGADAGDAGgdsgdsgfbshgshfshsfa";
    //2.生成token
    public static String createToken(Map<String,Object> body){
        //生成token
        SecretKey key = Keys.hmacShaKeyFor(sect.getBytes());
        return Jwts.builder()
                .setClaims(body)
                //设置过期时间
                .setExpiration(new Date(System.currentTimeMillis()+60*60*1000))
                .signWith(key)
                .compact();
    }
}
